import 'package:flutter/material.dart';
import 'package:hzy_project_template/config/config_index.dart';

import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';

class WechatPickerConfig {
  RequestType requestType = RequestType.image;
  AssetPickerConfig? pickerConfig;
  CameraPickerConfig cameraConfig = const CameraPickerConfig();
  Color? themeColor;
}

class WechatPickerTool {
  /*
   * 配置相册相机功能微信风格，只支持iOS和android
  
   * selectedAssets 选择的图片
   * maxAssets 最多个数
   * requestType: 相册支持的样式 图片 视频
   * pickerConfig 相册配置文件
   * cameraConfig 相机配置文件
   * type: 0 相册 1 相机
   * 
   * */
  static Future<List<AssetEntity>?> configWechatPickerTool({
    required BuildContext context,
    List<AssetEntity>? selectedAssets,
    int maxAssets = 1,
    RequestType requestType = RequestType.image,
    AssetPickerConfig? pickerConfig,
    CameraPickerConfig cameraConfig = const CameraPickerConfig(),
    Color? themeColor,
    int type = 0,
  }) async {
    List<AssetEntity>? imageList;

    if (type == 0) {
      imageList = await configGallery(
        context: context,
        selectedAssets: selectedAssets,
        maxAssets: maxAssets,
        requestType: requestType,
        themeColor: themeColor,
        pickerConfig: pickerConfig,
      );
    } else if (type == 1) {
      imageList = await configCamera(
        context: context,
        pickerConfig: cameraConfig,
      );
    }
    return imageList;
  }

  /// 相册
  /// 没有权限处理
  static configGallery({
    required BuildContext context,
    List<AssetEntity>? selectedAssets,
    int maxAssets = 1,
    RequestType requestType = RequestType.image,
    Color? themeColor,
    AssetPickerConfig? pickerConfig,
  }) async {
    return await AssetPicker.pickAssets(
      context,
      pickerConfig: pickerConfig ??
          AssetPickerConfig(
            maxAssets: maxAssets,
            selectedAssets: selectedAssets,
            requestType: requestType,
            themeColor: themeColor ?? HzyCommonColor().colthemes,
          ),
    );
  }

  /// 相机
  /// 没有权限处理
  static configCamera({
    required BuildContext context,
    CameraPickerConfig pickerConfig = const CameraPickerConfig(),
  }) async {
    return await CameraPicker.pickFromCamera(
      context,
      pickerConfig: pickerConfig,
    );
  }
}
